<?php

use yii\db\Migration;

class m171228_075607_create_article extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%article}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'title' => $this->string(255)->defaultValue(null)->comment('标题'),
                'cate_id' => $this->integer()->defaultValue(0)->comment('分类id'),
                'menu_id' => $this->smallInteger()->defaultValue(0)->comment('导航id'),
                'keyword' => $this->string(255)->defaultValue(null)->comment('关键词'),
                'picture' => $this->string(200)->defaultValue(null)->comment('图片'),
                'status' => $this->smallInteger(1)->defaultValue(1)->comment('1 显示 2 不显示'),
                'description' => $this->text()->defaultValue(null)->comment('描述'),
                'content' => $this->text()->defaultValue(null)->comment('描述'),
                'admin_id' => $this->integer()->defaultValue(0)->comment('管理员id'),
                'is_top' => $this->smallInteger(1)->defaultValue(0)->comment('是否置顶 （0 否 1 是）'),
                'sort_order' => $this->smallInteger()->defaultValue(0)->comment('排序'),
                'updated_at' => $this->integer()->defaultValue(0)->comment('编辑时间'),
                'created_at' => $this->integer()->defaultValue(0)->comment('添加时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%article}}');
        }
    }
}
